-1 when value is negative, 1 when it is positive, 0 when it is exactly 0.
sign(value) -> real| Name | Type |
|---|---|
value | real |
real
-1 when value is negative, 1 when it is positive, 0 when it is exactly 0. sign answers "which way," with no opinion at all about "how much."
Given a whole number, sign hands back a whole number; given a decimal, it hands back a decimal. sign_int does the same for whole numbers but refuses a decimal outright.
hsp = sign(xstart - x) * 2;Nudges this object 2 pixels toward wherever it spawned, every single frame, no matter how far away that is. This is the thing to notice about sign: the step size (2, here) is entirely up to the caller and never shrinks as the distance closes - so once this object is within 2 pixels of xstart, it overshoots and starts stepping back and forth across it forever, unless something else stops it. approach exists specifically to avoid that - it lands exactly on the target and stays there.
approachsign is the right tool when the STEP size itself should never change with distance - accelerating an object by a fixed amount every frame toward wherever a target currently is, for instance, rather than sliding smoothly to a stop beside it. approach is the right tool the moment "land exactly on the target and stop" is part of what is being asked for.
Two comparisons, hand-written - there is nothing in this file's usual "wraps a call into the Game Boy Advance module" family to reuse here, but it is still as cheap as this group gets.
Hand-written (two comparisons) - unlike almost everything else in this group, there is no single GBA-module call this wraps. Useful for "which way" without caring "how much": hsp += sign(target_x - x) moves one step toward target_x every frame regardless of how far away it is, where approach (below) would be the right call whenever the STEP size itself should also matter. Given a whole number it hands back a whole number; given a decimal it hands back a decimal. sign_int is the same call, for when you want a decimal refused outright.